﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace ZFB.Models.EntityConfig
{
    public class AdminUsersConfig :IEntityTypeConfiguration<T_AdminUsers>
    {
        public void Configure(EntityTypeBuilder<T_AdminUsers> builder)
        {
            builder.ToTable("T_AdminUsers");

            builder.Property(e => e.PhoneNum).IsUnicode(false);

            builder.Property(e => e.PasswordHash).IsUnicode(false);

            builder.Property(e => e.PasswordSalt).IsUnicode(false);

            builder.Property(e => e.Email).IsUnicode(false);

            
            builder.HasMany(e=>e.T_AdminLogs).WithOne(e=>e.T_AdminUsers).HasForeignKey(e => e.AdminUserId).OnDelete(DeleteBehavior.Restrict);
            
            builder.HasMany(e=>e.T_HouseAppointments).WithOne(e => e.T_AdminUsers).HasForeignKey(e => e.FollowAdminUserId).OnDelete(DeleteBehavior.Restrict); ;
            
            builder.HasOne(e=>e.T_Cities).WithMany(e=>e.T_AdminUsers).HasForeignKey(e => e.CityId).OnDelete(DeleteBehavior.Restrict);
            
            builder.HasMany(e=>e.T_Roles).WithMany(e=>e.T_AdminUsers).UsingEntity(m => m.ToTable("T_AdminUserRoles"));







        }
    }
}
